<?php

namespace common\models\cms;

use Yii;

/**
 * This is the model class for table "{{%cms_special_position}}".
 *
 * @property int $id
 * @property int $special_id
 * @property string|null $title
 * @property string|null $description
 * @property string|null $thumb
 * @property int $width
 * @property int $height
 * @property int $limits
 * @property int $listorder
 * @property string|null $template
 * @property int $show_title
 * @property int $map_id
 * @property string|null $map_data
 * @property string|null $model
 * @property int $model_id
 * @property int $status
 * @property int $created_at
 * @property int $updated_at
 * @property int $deleted_at
 */
class CmsSpecialPosition extends \common\db\ActiveRecord {

    use \common\traits\Constants;
    use \common\traits\WeblinkTrait;

    const STATUS_ACTIVE = 10;
    const STATUS_DEFAULT = 0;
    //
    const TEMPLATE_CELL = 'cell';
    const TEMPLATE_SLIPCARD = 'slipcard';
    const TEMPLATE_MEDIA = 'media';
    const TEMPLATE_AUDIOCARD = 'audiocard';

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%cms_special_position}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['special_id', 'width', 'height', 'limits', 'show_title', 'listorder', 'map_id', 'model_id', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['title', 'template'], 'string', 'max' => 50],
            [['description', 'thumb', 'map_data', 'model'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'special_id' => 'Special ID',
            'title' => 'Title',
            'description' => 'Description',
            'thumb' => 'Thumb',
            'width' => 'Width',
            'show_title' => 'Show Title',
            'height' => 'Height',
            'limits' => 'Limits',
            'listorder' => 'Listorder',
            'template' => 'Template',
            'map_id' => 'Map ID',
            'map_data' => 'Map Data',
            'model' => 'Model',
            'model_id' => 'Page ID',
            'status' => 'Status',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
            'deleted_at' => 'Deleted At',
        ];
    }

    public function getSpecial() {
        return $this->hasOne(CmsSpecial::class, ['id' => 'special_id']);
    }

    public function getArticles() {
        return $this->hasMany(CmsSpecialArticle::class, ['position_id' => 'id']);
    }

    public function getShowTitle() {
        return boolval($this->show_title);
    }

    public function getMapTitle() {
        return '查看更多';
    }

    public function getPageTitle() {
        return $this->title;
    }

}
